﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Examination
{
    public partial class UpdateForm : Form
    {
        public UpdateForm()
        {
            InitializeComponent();
        }

        private int id;


        public UpdateForm(int id, string title, string author)
        {
            InitializeComponent();

            this.id = id;
            txtName.Text = title;
            txtAuthor.Text = author;
        }

        /// <summary>
        /// 确认修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
            private void button1_Click(object sender, EventArgs e)
        {
            var res1 = MessageBox.Show("是否修改？", "提示", MessageBoxButtons.OKCancel);
            if (res1.Equals(DialogResult.OK))
            {
                string sql = string.Format("update Articles set Title='{0}',Author='{1}' where id={2}", txtName.Text,txtAuthor.Text,id);
                var res = DbHelper.AddSave(sql);
                if (res > 0)
                {
                    MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK);
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("修改失败", "提示", MessageBoxButtons.OK);
                }
        }
            else
            {
                var res2 = MessageBox.Show("取消成功", "提示", MessageBoxButtons.OK);
    }


}
        /// <summary>
        /// 取消按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
